<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>地图</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
        html,
        body,
        #container {
            height: 100%;
            visibility: hidden;
        }
        .info{
            width: 1px;
            visibility: hidden;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <form action="/HTML/userInfo" method="post" name="showUserInfoForm" >
        <a class="navbar-brand" href="javascript:history.go(-1)" name="savesubmit" id="savesubmit"> <img class="logo" src="/images/logo-white.png" th:text="'  '+'酒店列表'"></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar1" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
    </form>
    <form method="post" action="/HTML/mapToList">
        <li class="nav-item">
            <button class="btn ml-2 btn btn-outline-secondary "style="color:#ffffff" >列表形式展示搜索结果</button>
        </li>
    </form>
    <div class="collapse navbar-collapse" id="navbar1">
        <ul class="navbar-nav ml-auto">
            <li class="nav-item">
                <a class="btn ml-2 btn-outline-danger" href="/HTML/relogin">退出登录<span class="sr-only">(current)</span></a>
            </li>
            <li class="new-item">
                <a class="btn ml-2 btn-outline-success" href="/HTML/home">返回主页</a>
            </li>
            <form action="/HTML/lookOrderList" method="post" name="showUserOrderForm" th:value="${account}">
                <li class="nav-item">
                    <a class="btn ml-2 btn-outline-primary" href="javascript:showUserOrderForm.submit();">我的订单<span class="sr-only">(current)</span></a>
                </li>
            </form>
            <li class="nav-item">
                <a class="btn ml-2 btn-outline-warning" href="javascript:showUserInfoForm.submit();">个人资料</a>
            </li>
        </ul>
    </div>
</nav>

<div id="container"></div>
<div class="info">
    <input id='status' type="hidden">
    <input id='result' type="hidden">
    <input id="position"name="position"type="hidden">
</div>
<div>
    <form action="/HTML/searchByDistance" method="post" id="location">
    <input value="" id="lng" text="经度" type="hidden" name="longitude">
    <input value="" id="lat" text="纬度" type="hidden" name="latitude">
    </form>
</div>
<!--<a href="searchResultList.html">列表模式</a>-->
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=e27195e43f8628bcda450fcf8f5ec924"></script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
        resizeEnable: true
    });
    window.onload= AMap.plugin('AMap.Geolocation', function() {
        var geolocation = new AMap.Geolocation({
            // 是否使用高精度定位
            enableHighAccuracy: true,
            // 设置定位超时时间，
            timeout: 10000,
            // 定位按钮的停靠位置的偏移量
            buttonOffset: new AMap.Pixel(10, 20),
            //  定位成功后调整地图视野范围使定位位置及精度范围视野内可见
            zoomToAccuracy: true,
            //  定位按钮的排放位置
            buttonPosition: 'RB'
        })
        map.addControl(geolocation);
        geolocation.getCurrentPosition(function(status,result){
            if(status=='complete'){
                onComplete(result)
            }else{
                onError(result)
            }
        });
    })
    //解析定位结果
    function onComplete(data) {
        document.getElementById('status').innerHTML='定位成功'
        var str = [];
        str.push('定位结果：' + data.position);
        str.push('定位类别：' + data.location_type);
        if(data.accuracy){
            str.push('精度：' + data.accuracy + ' 米');
        }//如为IP精确定位结果则没有精度信息

        str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
        document.getElementById('result').innerHTML = str.join('<br>');
        //传回location
            document.getElementById("lng").value=data.position.getLng();
            document.getElementById("lat").value=data.position.getLat();
            var form=document.getElementById("location");
            form.submit();
//            var s = data.position();
//            S.ajax({
//                type: 'POST',
//                url: path + '/check/testPost',
//                contentType: "application/json",
//                data: JSON.stringify(array),
//                success: function (data) {
//                }
//            });
        }
    //解析定位错误信息
    function onError(data) {
        document.getElementById('status').innerHTML='定位失败'
        document.getElementById('result').innerHTML = '失败原因排查信息:'+data.message;
    }
    // 以下方式直接跳转
//    window.location.href='/HTML/searchByDistance';
    // 以下方式定时跳转
//    setTimeout("javascript:location.href='/HTML/searchByDistance'", 5000);

</script>
</body>
</html>




